/**
 * 
 */
package fhq.hcmute.qrcode.util;

import fhq.hcmute.qrcode.detector.PatternPoint;

/**
 * @author Hien Nguyen Le
 * @Email: nglehien@gmail.com
 */
public class MathUtils {
	public static final float getDistance(float fromX, float fromY, float toX,
			float toY) {
		float dx = toX - fromX;
		float dy = toY - fromY;
		float result = (float) Math.sqrt(dx * dx + dy * dy);
		return result;
	}

	public static final float getDistance(PatternPoint fromA, PatternPoint toB) {
		return getDistance(fromA.getX(), fromA.getY(), toB.getX(), toB.getY());
	}

	public static double getDegre(PatternPoint p1, PatternPoint p2) {
		PatternPoint p3 = new PatternPoint(p1.getX(), p2.getY(), 0);
		double d1 = Math.sqrt(Math.pow(p2.getX() - p3.getX(), 2)
				+ Math.pow(p2.getY() - p3.getY(), 2));
		double d2 = Math.sqrt(Math.pow(p1.getX() - p2.getX(), 2)
				+ Math.pow(p1.getY() - p2.getY(), 2));
		return Math.asin(d1 / d2) * 180 / Math.PI;
	}

	public static float crossVector(MyVector vectorA, MyVector vectorB) {
		return vectorA.x * vectorB.y - vectorA.y * vectorB.x;
	}

	public static final class MyVector {
		private int x;
		private int y;

		/**
		 * @param x
		 * @param y
		 */
		public MyVector(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public MyVector(PatternPoint pointA, PatternPoint pointB) {
			this.x = (int) (pointB.getX() - pointA.getX());
			this.y = (int) (pointB.getY() - pointA.getY());
		}

		public int getX() {
			return x;
		}

		public void setX(int x) {
			this.x = x;
		}

		public int getY() {
			return y;
		}

		public void setY(int y) {
			this.y = y;
		}
	}
}
